/*--------------------------------------------------------------
 * File: demo49.c 编码类型：C语言  UTF-8
 * Author WRS (1352509846@qq.com)
 * 功能: 计算标准差
 * Version 0.1
 * Date 2022-08-12 
 * 
 * @copyright Copyright (c) 2022
 * 
----------------------------------------------------------------*/
#include <stdio.h>
#include <math.h>

float calculateSD(float data[])
{
    float sum = 0;
    float mean;
    float stadardDeviation = 0;
    int i = 0;
    
    // 遍历一遍数组，求总和
    for(i=0; i<10; i++)
    {
        sum += data[i];
    }
    mean = sum / 10;    // 求平均
    for(i=0; i<10; ++i)
    {
        stadardDeviation += pow((data[i] - mean),2);
    }
    return sqrt(stadardDeviation / 10);

}

int main(int argc, char const *argv[])
{
    float data[10] = {0};
    printf("请输入10个数:");
    
    for(int i=0; i<10; i++)
    {
        scanf("%f",&data[i]);
    }
    printf("平均差是：%f\n", calculateSD(data));

    return 0;
}
